import gulp from "gulp";
import chalk from "chalk";
import deployInteract from "./deploy/interact.js";
import distBuild from "./deploy/build.js";
import versionManage from "./deploy/version.js";
import compressFile from "./deploy/compress.js";
import uploadArchive from "./deploy/upload.js";

const log = console.log;

const { series } = gulp;

let deployConfig;

const interactTask = async (cb) => {
  const answers = await deployInteract();
  deployConfig = answers;
  cb();
};

const versionTask = (cb) => {
  log(
    chalk.magenta(
      "****************************版本管理******************************"
    )
  );
  versionManage(deployConfig);
  cb();
};

const buildTask = (cb) => {
  log(
    chalk.magenta(
      "****************************WEBPACK打包***************************"
    )
  );
  distBuild(deployConfig, () => {
    cb();
  });
};

const compressTask = async (cb) => {
  log(
    chalk.magenta(
      "*******************************压缩*******************************\n"
    )
  );
  await compressFile();
  cb();
};

const uploadTask = (cb) => {
  log(
    chalk.magenta(
      "*******************************上传*******************************\n"
    )
  );
  uploadArchive(deployConfig);
  cb();
};

export default series(
  interactTask,
  versionTask,
  buildTask,
  compressTask,
  uploadTask
);
